// JavaScript Document
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
var is_mac = userAgent.indexOf('mac') != -1;

if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(C, B) {
        if (B == null) {
            B = 0
        } else {
            if (B < 0) {
                B = Math.max(0, this.length + B)
            }
        } for (var A = B; A < this.length; A++) {
            if (this[A] === C) {
                return A
            }
        } return -1
    }
} if (!Array.prototype.lastIndexOf) {
    Array.prototype.lastIndexOf = function(C, B) {
        if (B == null) {
            B = this.length - 1
        } else {
            if (B < 0) {
                B = Math.max(0, this.length + B)
            }
        } for (var A = B; A >= 0; A--) {
            if (this[A] === C) {
                return A
            }
        } return -1
    }
} if (!Array.prototype.forEach) {
    Array.prototype.forEach = function(C, D) {
        var A = this.length;
        for (var B = 0; B < A; B++) {
            C.call(D, this[B], B, this)
        }
    }
} if (!Array.prototype.filter) {
    Array.prototype.filter = function(D, E) {
        var A = this.length;
        var C = [];
        for (var B = 0; B < A; B++) {
            if (D.call(E, this[B], B, this)) {
                C.push(this[B])
            }
        } return C
    }
} if (!Array.prototype.map) {
    Array.prototype.map = function(D, E) {
        var A = this.length;
        var C = [];
        for (var B = 0; B < A; B++) {
            C.push(D.call(E, this[B], B, this))
        } return C
    }
} if (!Array.prototype.some) {
    Array.prototype.some = function(C, D) {
        var A = this.length;
        for (var B = 0; B < A; B++) {
            if (C.call(D, this[B], B, this)) {
                return true
            }
        } return false
    }
} if (!Array.prototype.every) {
    Array.prototype.every = function(C, D) {
        var A = this.length;
        for (var B = 0; B < A; B++) {
            if (!C.call(D, this[B], B, this)) {
                return false
            }
        } return true
    }
} Array.prototype.contains = function(A) {
    return this.indexOf(A) != -1
};
Array.prototype.copy = function(A) {
    return this.concat()
};
Array.prototype.insertAt = function(B, A) {
    this.splice(A, 0, B)
};
Array.prototype.insertBefore = function(C, B) {
    var A = this.indexOf(B);
    if (A == -1) {
        this.push(C)
    } else {
        this.splice(A, 0, C)
    }
};
Array.prototype.removeAt = function(A) {
    this.splice(A, 1)
};
Array.prototype.remove = function(B) {
    var A = this.indexOf(B);
    if (A != -1) {
        this.splice(A, 1)
    }
};
if (!String.prototype.toQueryParams) {
    String.prototype.toQueryParams = function() {
        var F = {};
        var G = this.split("&");
        var D = /([^=]*)=(.*)/;
        for (var B = 0; B < G.length; B++) {
            var A = D.exec(G[B]);
            if (!A) {
                continue
            } var C = decodeURIComponent(A[1]);
            var E = A[2] ? decodeURIComponent(A[2]) : undefined;
            if (F[C] !== undefined) {
                if (F[C].constructor != Array) {
                    F[C] = [F[C]]
                } if (E) {
                    F[C].push(E)
                }
            } else {
                F[C] = E
            }
        } return F
    }
} if (!String.prototype.trim) {
    String.prototype.trim = function() {
        var A = /^\s+|\s+$/g;
        return function() {
            return this.replace(A, "")
        }
    } ()
} if (!String.prototype.getLength) {
    String.prototype.getLength = function() {
        var A = /[^\x00-\xff]/g;
        return function() {
            return this.replace(A, "**").length
        }
    } ()
} if (!String.prototype.replaceAll) {
    String.prototype.replaceAll = function(B, A) {
        return this.replace(new RegExp(B, "gm"), A)
    }
}
Math.randomInt = function(A) {
    return Math.floor(Math.random() * (A + 1))
};

//FixPrototypeForGecko
if(is_moz && window.HTMLElement) {
	HTMLElement.prototype.__defineSetter__('outerHTML', function(sHTML) {
        	var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var df = r.createContextualFragment(sHTML);
		this.parentNode.replaceChild(df,this);
		return sHTML;
	});

	HTMLElement.prototype.__defineGetter__('outerHTML', function() {
		var attr;
		var attrs = this.attributes;
		var str = '<' + this.tagName.toLowerCase();
		for(var i = 0;i < attrs.length;i++){
			attr = attrs[i];
			if(attr.specified)
			str += ' ' + attr.name + '="' + attr.value + '"';
		}
		if(!this.canHaveChildren) {
			return str + '>';
		}
		return str + '>' + this.innerHTML + '</' + this.tagName.toLowerCase() + '>';
        });

	HTMLElement.prototype.__defineGetter__('canHaveChildren', function() {
		switch(this.tagName.toLowerCase()) {
			case 'area':case 'base':case 'basefont':case 'col':case 'frame':case 'hr':case 'img':case 'br':case 'input':case 'isindex':case 'link':case 'meta':case 'param':
			return false;
        	}
		return true;
	});
	HTMLElement.prototype.click = function(){
		var evt = this.ownerDocument.createEvent('MouseEvents');
		evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
		this.dispatchEvent(evt);
	}
	
	HTMLElement.prototype.__defineGetter__("children",     
		 function () {     
			 var returnValue = new Object();     
			 var number = 0;     
			 for (var i=0; i<this.childNodes.length; i++) {     
				 if (this.childNodes[i].nodeType == 1) {     
					 returnValue[number] = this.childNodes[i];     
					 number++;
				 }     
			 }     
			 returnValue.length = number;     
			 return returnValue;     
		 }     
	 );
} 

var Shoes = YAHOO;
var $D = Shoes.util.Dom;
var $E = Shoes.util.Event;
var $ = $D.get;

(function(){
		  
	var ua = navigator.userAgent.toLowerCase();
	
	var opera = ua.indexOf("opera")!=-1,
		safari = ua.indexOf("safari")!=-1,
		gecko = !opera && !safari && ua.indexOf("gecko")>-1,
		ie = !opera && ua.indexOf("msie")!=-1,
		ie6 = !opera && ua.indexOf("msie 6")!=-1,
		ie7 = !opera && ua.indexOf("msie 7")!=-1,
		ie8 = !opera && ua.indexOf("msie 8")!=-1;
		
	Shoes.namespace("Tools");
	
	Shoes.Tools = {
		isOpera : opera,
		isSafari : safari,
		isGecko : gecko,
		isIE : ie,
		isIE6 : ie6,
		isIE7 : ie7,
		isIE8 : ie8,
		getCookie : function (name){
			var cookie=document.cookie.match("(?:^|;)\\s*" + name + "=([^;]*)");
			return cookie ? decodeURI(cookie[1]) : "";
		},
		setCookie : function (name,value,expires,domain,path){
			value = encodeURI(value);
			value += (domain) ? "; domain=" + domain : "";
			value += (path) ? "; path=" + path : "";
			if(expires){
				var expire=new Date();
				expire.setTime( expire.getTime() + (expires*86400000) );
				value += "; expires="+expire.toGMTString()
			}
			document.cookie = name + "=" + value;
		},
		removeCookie : function (name){
			this.setCookie(name,"",-1);
		},
		isValidEmail : function(email){
			if (email.search(/[_a-zA-Z\d\-\.]+@[_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+$/) != -1){
				return true;
			}else{
				return false;
			}
		},
		trim:function(s){
			return A.replace(/(^\s*)|(\s*$)/g,"")
		},
		isHttp: function(s){
		    try{
		        return /(http:\/\/)?([\w-]+\.)+[\w-]+(\/[\w-\.\/?%&=]*)?/.test(s);
		    }catch(e){
		        return false;
		    }
		},
		isNumber : function(s){
		    try{
		        return /^\d+$/.test(s);
		    }catch(e){
		        return false;
		    }
		}
	};
	
})();

function _attachEvent(obj, evt, func, eventobj) {
	eventobj = !eventobj ? obj : eventobj;
	if(obj.addEventListener) {
		obj.addEventListener(evt, func, false);
	} else if(eventobj.attachEvent) {
		obj.attachEvent("on" + evt, func);
	}
}

function getcookie(name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}

function setcookie(cookieName, cookieValue, seconds, path, domain, secure) {
	var expires = new Date();
	expires.setTime(expires.getTime() + seconds * 1000);
	domain = !domain ? cookiedomain : domain;
	path = !path ? cookiepath : path;
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '/')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}

function doane(event) {
	e = event ? event : window.event;
	if(is_ie) {
		e.returnValue = false;
		e.cancelBubble = true;
	} else if(e) {
		e.stopPropagation();
		e.preventDefault();
	}
}

function display(id) {
	$(id).style.display = $(id).style.display == '' ? 'none' : '';
}

function checkall(form, prefix, checkall) {
	var checkall = checkall ? checkall : 'chkall';
	count = 0;
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.name && e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
			e.checked = form.elements[checkall].checked;
			if(e.checked) {
				count++;
			}
		}
	}
	return count;
}

///obj全选按钮,name操作的选择框名字
function checkAll(obj,name) {
	var el = document.getElementsByTagName('input');
	var len = el.length;
	for(var i=0; i<len; i++){
		if((el[i].type=="checkbox") && (el[i].name==name)){
			el[i].checked = obj.checked;
		}
	}
}

function getCheckedItemIds(form,name) {
	var oForm = $(form);
	var oItem = oForm.getElementsByTagName("input");
	var checkedItemIds = new Array();
	var i = 0;
	while (i < oItem.length) {
		if(oItem[i].type=="checkbox" && oItem[i].name==name){
			if(oItem[i].checked){
				checkedItemIds.pop(oItem[i].value);
			}
		}
		i++;
	}
	return checkedItemIds.join(",");
}


function getCheckedItemCount(form,name) {
	var oForm = $(form);
	var oItem = oForm.getElementsByTagName("input");
	var count=0;
	var i = 0;
	while (i < oItem.length) {
		if((oItem[i].type=="checkbox") && oItem[i].name==name){
			if(oItem[i].checked){
				count ++;
			}
		}
		i++;
	}
	return count;
}

DataGridPanel = function(){
	var el = arguments[0];
	var datatable = $(el);
	var thead = datatable.getElementsByTagName("thead")[0];
	var hasCheckbox = typeof(thead.getElementsByTagName("input")[0])=="object";
	var th = thead.getElementsByTagName("td");
	for(var i=1;i<th.length;i++){
		th[i].className = "x-hd";
		th[i].onmouseover = function(){
			this.className = "x-hd-over";
		}
		th[i].onmouseout = function(){
			this.className = "x-hd";
		}
	}
	var tfoot = datatable.getElementsByTagName("tfoot")[0];
	if(tfoot){
		datatableLength=datatable.rows.length-1;
	}else{
		datatableLength = datatable.rows.length;
	}
	for(var i=1;i<datatableLength;i++){
		if(hasCheckbox){
			rowsclick(datatable.rows[i]);
		}
		rowsover(datatable.rows[i]);
		rowsout(datatable.rows[i]);
	}
	var chkall = thead.getElementsByTagName("input")[0];
	if(chkall && hasCheckbox){
		chkall.onclick = function(){
			for(var i=1;i<datatable.rows.length;i++){
				var checkItem = datatable.rows[i].getElementsByTagName("input")[0];
				if(checkItem){
					if(this.checked){
						if(datatable.rows[i].className.indexOf("x-row-selected")>0){
							datatable.rows[i].className += " x-row-selected ";
						}
					}else{
						datatable.rows[i].className = datatable.rows[i].className.replace("x-row-selected","");
					}
					checkItem.checked = this.checked;
				}
			}
		}
	}
	function rowsclick(row){
		row.onclick = function(){
			var checkbox = this.getElementsByTagName("input")[0];
			if(this.className.indexOf("x-row-selected")>0){
				this.className = this.className.replace("x-row-selected","");
				if(checkbox){
					checkbox.checked = false;
				}
			}else{
				this.className += " x-row-selected ";
				if(checkbox){
					checkbox.checked = true;
				}
			}
		}
	}
	function rowsover(row){
		row.onmouseover = function(){
			this.className = this.className.replace(/x-row$/g,"x-row-over");
		}
	}
	function rowsout(row){
		row.onmouseout = function(){
			this.className = this.className.replace(/x-row-over$/g,"x-row");
		}
	}
}

function ShoesMenu(menuId){
	if(!menuId)return false;
	this.smenu = $(menuId);
	this.speed = 3;
	this.oneSmOnly = false;
	this.isanim = false;
}

ShoesMenu.prototype = {
	init : function(){
		var sm = this;
		var submenus = sm.smenu.getElementsByTagName("ul");
		//搜索classname = submenu的节点
		for(var i=0;i<submenus.length;i++){
			submenus[i].parentNode.children[0].onclick = function(){
				sm.toggleMenu(this.parentNode);
				if(this.tagName=="A"){
					if(this.href.indexOf("#")>0){
						return false;
					}
				}
			}
		}
	},
	toggleMenu : function(submenu){
		switch(submenu.className){
			case "collapsed":
				this.expandMenu(submenu);
				return false;
				break;
			case "expand":
				this.collapseMenu(submenu);
				return false;
				break;
			default:
				return;
		}
	},
	expandMenu : function(submenu){
		submenu.className = "expand";
		this.collapseOthers(submenu);
	},
	collapseMenu :function(submenu){
		submenu.className = "collapsed";
	},
	collapseOthers : function(submenu) {
		if (this.oneSmOnly) {
			var sm = this;
			var submenus = sm.smenu.children;
			for (var i = 0; i < submenus.length; i++)
				if (submenus[i] != submenu && submenus[i].className != "collapsed" && submenus[i].className != "" && submenus[i].className != "last") 
					this.collapseMenu(submenus[i]);
		}
	},
	/* 作用不大 */
	expandAll:function(){
		var oldOneSmOnly = this.oneSmOnly;
		this.oneSmOnly = false;
		var sm = this;
		var submenus = sm.smenu.children;
		for (var i = 0; i < submenus.length; i++)
			if (submenus[i].className == "collapsed" && submenus[i].className != "" && submenus[i].className != "last")
				this.expandMenu(submenus[i]);
		this.oneSmOnly = oldOneSmOnly;
	},
	collapseAll :function(){
		var sm = this;
		var submenus = sm.smenu.children;
		for (var i = 0; i < submenus.length; i++)
			if (submenus[i].className != "collapsed" && submenus[i].className != "" && submenus[i].className != "last")
				this.collapseMenu(submenus[i]);
	}
};

function SDMenu(id) {
	if (!document.getElementById || !document.getElementsByTagName)
		return false;
	this.menu = document.getElementById(id);
	this.submenus = this.menu.getElementsByTagName("div");
	this.remember = true;
	this.speed = 3;
	this.markCurrent = true;
	this.oneSmOnly = false;
}
SDMenu.prototype.init = function() {
	var mainInstance = this;
	for (var i = 0; i < this.submenus.length; i++)
		this.submenus[i].getElementsByTagName("span")[0].onclick = function() {
			mainInstance.toggleMenu(this.parentNode);
		};
	if (this.markCurrent) {
		var links = this.menu.getElementsByTagName("a");
		for (var i = 0; i < links.length; i++)
			if (links[i].href == document.location.href) {
				links[i].className = "current";
				break;
			}
	} 
	if (this.remember) {
		var regex = new RegExp("sdmenu_" + encodeURIComponent(this.menu.id) + "=([01]+)"); 
		var match = regex.exec(document.cookie);
		if (match) {
			var states = match[1].split("");
			for (var i = 0; i < states.length; i++)
				this.submenus[i].className = (states[i] == 0 ? "collapsed" : "");
		}
	}
};

SDMenu.prototype.toggleMenu = function(submenu) { 
	if (submenu.className == "collapsed")
		this.expandMenu(submenu);
	else
		this.collapseMenu(submenu);
};

SDMenu.prototype.expandMenu = function(submenu) {
	var fullHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
	var links = submenu.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++)
	fullHeight += links[i].offsetHeight;
	var moveBy = Math.round(this.speed * links.length);
	var mainInstance = this;
	var intId = setInterval(function() {
		 var curHeight = submenu.offsetHeight; 
		 var newHeight = curHeight + moveBy;
		 if (newHeight < fullHeight)
			submenu.style.height = newHeight + "px";
		 else {
			 clearInterval(intId);
			 submenu.style.height = "";
			 submenu.className = "";
			 mainInstance.memorize();
		 }
	}, 30);
	this.collapseOthers(submenu);
};

SDMenu.prototype.collapseMenu = function(submenu) {
	var minHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
	var moveBy = Math.round(this.speed * submenu.getElementsByTagName("a").length);
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = submenu.offsetHeight;
		var newHeight = curHeight - moveBy;
		if (newHeight > minHeight)
			submenu.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			submenu.style.height = "";
			submenu.className = "collapsed";
			mainInstance.memorize();
		}
	}, 30);
};

SDMenu.prototype.collapseOthers = function(submenu) {
	if (this.oneSmOnly) {
		for (var i = 0; i < this.submenus.length; i++)
			if (this.submenus[i] != submenu && this.submenus[i].className != "collapsed") 
				this.collapseMenu(this.submenus[i]);
	}
};

SDMenu.prototype.expandAll = function() {
	var oldOneSmOnly = this.oneSmOnly;
	this.oneSmOnly = false;
	for (var i = 0; i < this.submenus.length; i++)
	if (this.submenus[i].className == "collapsed")
	this.expandMenu(this.submenus[i]);
	this.oneSmOnly = oldOneSmOnly;
};

SDMenu.prototype.collapseAll = function() {
	for (var i = 0; i < this.submenus.length; i++)
		if (this.submenus[i].className != "collapsed")
			this.collapseMenu(this.submenus[i]);
};

SDMenu.prototype.memorize = function() {
	if (this.remember) {
		var states = new Array();
		for (var i = 0; i < this.submenus.length; i++)
			states.push(this.submenus[i].className == "collapsed" ? 0 : 1);
		var d = new Date();
		d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000));
		document.cookie = "sdmenu_" + encodeURIComponent(this.menu.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + "; path=/";
	}
};

var searchTypeList = [
	{ searchType: "sale", tips: "请输入产品名称", action: "http://www.shoes.net.cn/trade/search.htm", searchId: "4" },
	{ searchType: "buy", tips: "请输入产品名称", action: "http://www.shoes.net.cn/trade/search.htm", searchId: "5" },
	{ searchType: "company", tips: "请输入公司名称", action: "http://www.shoes.net.cn/company/search.htm", searchId: "3" },
	{ searchType: "product", tips: "请输入产品名称", action: "http://www.shoes.net.cn/product/search.htm", searchId: "2" },
	{ searchType: "brand", tips: "请输入品牌名称", action: "http://brand.shoes.net.cn/search.htm", searchId: "7" },
	{ searchType: "news", tips: "请输入关键字", action: "http://www.shoes.net.cn/news/search.htm", searchId: "6" },
	{ searchType: "job", tips: "请输入关键字", action: "http://www.shoes.net.cn/hr/companyList.htm", searchId: "8" }
];

function ChangeSearchType() {
    var searchForm = $("memberQuickSearch");
	var keyword = $("keyword");
	var searchType = $("searchType").options[$("searchType").selectedIndex].value;
	for (var i = 0; i < searchTypeList.length; i++) {
	    if (searchTypeList[i].searchType == searchType) {

	        if (keyword.value.indexOf("请输入") != -1) {
	            keyword.value = searchTypeList[i].tips;
	        }
	        $("tradeType").value = searchType;
	        	        
	        searchForm.action = searchTypeList[i].action;
	        oldSearchTypeItem = searchTypeList[i];
	        break;
	    }
	}
}

function Tip(controls){
	if(!controls)return;
	for(var id in controls){
		var tags = document.getElementsByTagName("*");
		var arr = new Array();
		for(var i=0;i<tags.length;i++){
			if(tags[i].id==id){
				arr[arr.length]=$(tags[i]);
			}
		}
		(function(){
			$E.on(arr,"mouseover",function(ev,el){
				var xy = $D.getXY(this);
				var w = this.offsetWidth;
				var h = this.offsetHeight;
				var floatDivXY = [2];
				if($("seoTip")){
					document.body.removeChild($("seoTip"));
				}
				var floatDiv = document.createElement("div");
				floatDiv.id = "seoTip";
				floatDiv.className = "seo-tip";
				floatDiv.innerHTML = controls[el.idx];
				document.body.appendChild(floatDiv);
				if(Shoes.Tools.isIE6&&!Shoes.Tools.isIE7&&!Shoes.Tools.isIE8){
					$D.setStyle(floatDiv,"height",floatDiv.offsetHeight + "px");
					$D.setStyle(floatDiv,"padding","0");
					$D.setStyle(floatDiv,"border","none");
					floatDiv.innerHTML = "<div style=\"zoom:1;border:1px solid #000;padding:5px 10px;\">"+controls[el.idx]+"</div><iframe style=\"position:absolute;top:0;left:0;width:"+eval(floatDiv.offsetWidth)+"px;height:"+eval(floatDiv.offsetHeight)+"px;z-index:-1;\"></iframe>";
				}
				var floatH = floatDiv.offsetHeight;
				floatDivXY[0] = xy[0] + Math.ceil(w / 2);
				floatDivXY[1] = xy[1] - floatH - 5;
				$D.setXY(floatDiv, floatDivXY);
			},{idx:id});
			$E.on(arr,"mouseout",function(){
				var seoTip = $("seoTip");
				if(seoTip){
					document.body.removeChild(seoTip);
				}
			});
		})();
	}
}